// pages/index/page/blessing/blessing.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowWidth: 0, // 可使用窗口宽度
    windowHeight: 0, // 可使用窗口高度
    bixiu: 0, 
    chanye: 0,
    shangye: 0,
    jiaoju: 0,
    zixun: 0,
    total_number:0,
    uid:'',
    myUid:'',
    num:'0'
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.uid > 0) {
      that.setData({
        myUid: options.uid
      })
    }
    var that = this
    that.getNumber()
    that.getUid()
    that.getid()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    const vm = this
    vm.setData({
      statusBarHeight: getApp().globalData.statusBarHeight,
      titleBarHeight: getApp().globalData.titleBarHeight
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: '#000000'
    });
    
  },
  getUid: function () {
    var that = this
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/getUid',
      data: {
        myId: app.globalData.myId
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status === 1) {
          that.setData({
            uid: res.data.uid
          })

          wx.hideLoading()
        } else {
        }
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  getid: function () {
    console.log(0)
    var that = this
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/Index',
      data: {
        myId: app.globalData.myId,
        uid: that.data.myUid
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.status === 1) {
          console.log(res)
          that.setData({
            fu: res.data.fu,
            img_url: res.data.img_url,
            hiddenbox: 'show'
          })

          wx.hideLoading()
        } else if (res.data.status === 2) {
          console.log(res)
          that.setData({
            hiddenbox: 'hide'
          })
        } else {

        }
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  getNumber:function(){
    console.log('sdfs')
    var that = this
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/WuFu/myPack',
      data: {
        myId: app.globalData.myId
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.status === 1) {
          that.setData({
            bixiu: res.data.data.bixiu,
            chanye: res.data.data.chanye,
            shangye: res.data.data.shangye,
            jiaoju: res.data.data.jiaoju,
            zixun: res.data.data.zixun,
            total_number: res.data.total_number
          })
         
          wx.hideLoading()
        } else {
          console.log(res)
        }
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  q: function () {
    wx.navigateBack({ changed: true })
  },
  qq: function () {
    wx.switchTab({
      url: '/pages/index/index',
    });
  },
  toBlessingWriter: function () {
    wx.navigateTo({
      url: '../blessingWriter/blessingWriter?uid='+this.data.uid,
    });
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (ops) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      title: '集齐五福可获得周骊晓老师墨宝一副',

      path: "pages/index/page/blessing/blessing?uid=" + this.data.uid,// 用户点击首先进入的当前页面
      success: function (res) {
        // 转发成功
        console.log("转发成功:");
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:");
      }
    }
  }
})